package com.xyz.graph.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class OpTimizeAspect {

    @Pointcut("@annotation(com.xyz.graph.common.annotation.OptimizeLog)")
    private void pointcut(){}

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable{
        Logger logger = LoggerFactory.getLogger(joinPoint.getTarget().getClass());
        String clazzName = joinPoint.getTarget().getClass().getName();
        String methodName = joinPoint.getSignature().getName();
        long start = System.currentTimeMillis();
        logger.info("{}: {}: start...",clazzName,methodName);
        Object result = joinPoint.proceed();
        long time = System.currentTimeMillis()-start;
        logger.info("{}: {}: : end... cost time: {} ms",clazzName,methodName,time);
        return result;
    }
}
